﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MirthToTFS
{
    public  class MirthBackupDAL
    {
        private string DatabaseConnection { get; set; }
        public MirthBackupDAL(string databaseConnectionString)
        {
            DatabaseConnection = databaseConnectionString;
        }

        public   IQueryable<MirthBackup> ListActiveMirthTargets()
        {
            var db = new MirthBackupDataContext(DatabaseConnection);
            return db.MirthBackups.Where(x => x.IsActive == true);
        }

        public   void MarkBackupAsSuccessful(short id)
        {
            using (var db = new MirthBackupDataContext(DatabaseConnection))
            {
                var backup = db.MirthBackups.SingleOrDefault(x => x.ID == id);
                backup.LastCompletedOn = DateTime.Now;
                db.SubmitChanges();
            }
        }

    }
}
